package doubleball;

import java.util.Scanner;

/**
 * 双色球的界面类
 */
public class DoubleBall {
    /**
     * 系统产生的红球数组
     */
    private Ball [] sysRedBall = new Ball[6];
    /**
     * 系统产生蓝球
     */
    private Ball sysBlueBall = new Ball("蓝球");
    /**
     * 用户输入的红球数组
     */
    private Ball [] inputRedBall = new Ball[6];
    /**
     * 用户输入的蓝球
     */
    private Ball inputBlueBall;
    private Scanner sc = new Scanner(System.in);

    /**
     * 程序的流程控制
     */
    public void process(){
        this.initSysBall();
        this.initInputBall();
        this.printWinInfo();
    }

    /**
     * 随机产生6个红球和1个蓝球
     */
    public void initSysBall(){
        for(int i = 0;i < sysRedBall.length;i++) {
            sysRedBall[i] = new Ball("红球");
            for(int j = 0;j < i;j++) {
                if(sysRedBall[i].getValue() == sysRedBall[j].getValue()) {
                    i--;
                    break;
                }
            }
        }
        for(int i = 0;i < sysRedBall.length;i++) {
            System.out.print(sysRedBall[i].getValue() + ",");
        }
        System.out.println(sysBlueBall.getValue());
    }
    /**
     * 用户输入6个红球和1个蓝球
     */
    public void initInputBall(){
        // 用户输入六颗红球
        for(int i = 0;i < inputRedBall.length;i++) {
            System.out.println("请输入第"+(i+1)+"个红球");
            inputRedBall[i] = new Ball(sc.nextInt(),"红球");

        }
        // 用户输入蓝球
        System.out.println("请输入蓝球号码：");
        inputBlueBall = new Ball(sc.nextInt(),"蓝球");
    }
    /**
     * 打印中奖情况
     */
    public void printWinInfo(){
        // 红球相等数量的计数器
        int redBallCount = 0;
        for(int i = 0;i < sysRedBall.length;i++) {
            for(int j = 0;j < inputRedBall.length;j++) {
                if(sysRedBall[i].getValue() == inputRedBall[j].getValue()) {
                    redBallCount++;
                }
            }
        }
        // 将比较的结果进行判断并输出中奖情况
        if(redBallCount == 6 && sysBlueBall.getValue() == inputBlueBall.getValue()) {
            System.out.println("恭喜你，中了一等奖");
        }else if(redBallCount == 6) {
            System.out.println("恭喜你，中了二等奖");
        }else if(redBallCount == 5 && sysBlueBall.getValue() == inputBlueBall.getValue()) {
            System.out.println("恭喜你，中了三等奖");
        }else if(redBallCount == 5 || (redBallCount == 4 && sysBlueBall.getValue() == inputBlueBall.getValue())) {
            System.out.println("恭喜你，中了四等奖");
        }else if(redBallCount == 4 || (redBallCount == 3 && sysBlueBall.getValue() == inputBlueBall.getValue())) {
            System.out.println("恭喜你，中了五等奖");
        }else if(sysBlueBall.getValue() == inputBlueBall.getValue()) {
            System.out.println("恭喜你，中了六等奖");
        }else {
            System.out.println("再接再厉，下次一定是你");
        }
    }

}
